package com.walter.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.walter.domain.TeacherInfo;
import com.walter.service.TeacherInfoService;
import com.walter.service.impl.TeacherInfoServiceImpl;

public class TeacherInfoServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private TeacherInfoService ts = new TeacherInfoServiceImpl();

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// 获取第几页
		String page0="1";
		page0= request.getParameter("page");
		if(page0==""||page0==null){
			page0="1";
		}
		int page = Integer.parseInt(page0);
		// 1.调用Service查询所有客户
		//List<TeacherInfo> list = ts.getAll();
		List<TeacherInfo> list = ts.getAllByPage(page);
		long count = ts.getCount();
		
		long lastPage= count%3==0?count/3:count/3+1;
		// 2.将客户列表放入request域
		request.setAttribute("list", list);
		request.setAttribute("count", count);
		request.setAttribute("countPage", page);
		request.setAttribute("lastPage", lastPage);
		// 3.转发到list.jsp显示

		request.getRequestDispatcher("/jsp/index.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
}